/*
 * Copyright (C) 2004-2010  Autodesk, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of version 2.1 of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "stdafx.h"
#include "FdoCMSXmlGlobals.h"
#include "FdoCMSYahooGetMapURL.h"
#include <FdoCommonStringUtil.h>
#include <OWS/FdoOwsGlobals.h>

FdoCMSYahooGetMapURL::FdoCMSYahooGetMapURL (FdoDouble dCenterLat,
                                    FdoDouble dCenterLon,
                                    FdoInt32 iZoomLevel,
                                    FdoSize height,
                                    FdoSize width,
                                    FdoString* imageFormat,
                                    FdoString* mapType) 
    : m_dStartLat(dCenterLat), 
      m_dStartLon(dCenterLon),
      m_iZoomLevel(iZoomLevel),
      m_Height(height),
      m_Width(width), 
      m_Format(imageFormat ? imageFormat : L""), 
      m_MapType(mapType ? mapType : L"")
{
}

FdoCMSYahooGetMapURL::FdoCMSYahooGetMapURL ():
        m_dStartLat(0.0),
        m_dStartLon(0.0),
        m_iZoomLevel(0),
        m_Height(0),
        m_Width(0)
{
}

FdoCMSYahooGetMapURL* FdoCMSYahooGetMapURL::Create (FdoDouble dCenterLat, 
                                            FdoDouble dCenterLon,
                                            FdoInt32 iZoomLevel,
                                            FdoSize height,
                                            FdoSize width,
                                            FdoString* imageFormat,
                                            FdoString* mapType) 
{
    return new FdoCMSYahooGetMapURL (dCenterLat, dCenterLon, iZoomLevel, height, width, imageFormat, mapType);
}

FdoCMSYahooGetMapURL::~FdoCMSYahooGetMapURL ()
{
}

FdoStringP FdoCMSYahooGetMapURL::EncodeKVP()
{

    //// Add "appid" parameters in the request 
    //FdoStringP ret = FdoCMSXmlGlobals::CMSYahooRequestLatitude;
    //ret += FdoOwsGlobals::Equal;
    //ret += m_appId;

    //// Add "latitude" parameters in the request    
    //ret += FdoOwsGlobals::And;
    //ret = FdoCMSXmlGlobals::CMSYahooRequestLatitude;
    //ret += FdoOwsGlobals::Equal;
    //ret += FdoStringP::Format(L"%lf", m_dStartLat);

    //// Add "longtitude" parameters in the request
    //ret += FdoOwsGlobals::And;
    //ret += FdoCMSXmlGlobals::CMSYahooRequestWidth;
    //ret += FdoOwsGlobals::Equal;
    //ret += FdoStringP::Format(L"%lf", m_dStartLon);

    //// Add "image_width" parameters in the request
    //ret += FdoOwsGlobals::And;
    //ret += FdoCMSXmlGlobals::CMSYahooRequestWidth;
    //ret += FdoOwsGlobals::Equal;
    //ret += FdoStringP::Format(L"%d", m_Width);

    //// Add "image_height" parameters in the request
    //ret += FdoOwsGlobals::And;
    //ret += FdoCMSXmlGlobals::CMSYahooRequestHeight;
    //ret += FdoOwsGlobals::Equal;
    //ret += FdoStringP::Format(L"%d", m_Height);

    //// Add "zoom" parameters in the request
    //ret += FdoOwsGlobals::And;
    //ret += FdoCMSXmlGlobals::CMSYahooRequestZoom;
    //ret += FdoOwsGlobals::Equal;
    //ret += FdoStringP::Format(L"%d", m_iZoomLevel);
    //
    ////// Translate to a valid HTTP request
    //ret = ret.Replace(L" ", L"%20"); 

    // Test String
    //   FdoStringP ret = L"appid=i3M.d9_V34G5V.aulAsZT2Y7WMCiQgQEBJ6DIDhRccnkehVJLwBWbMG9TUogi9liNw--&latitude=0&longitude=0&zoom=12";
      // ret = ret.Replace(L" ", L"%20"); 
       // image_width=500&image_height=500&
    // FdoStringP ret = L"appid=i3M.d9_V34G5V.aulAsZT2Y7WMCiQgQEBJ6DIDhRccnkehVJLwBWbMG9TUogi9liNw--&latitude=-89.9&longitude=-179.9&zoom=12&image_width=1024&image_height=1024";
    FdoStringP ret = L"appid=i3M.d9_V34G5V.aulAsZT2Y7WMCiQgQEBJ6DIDhRccnkehVJLwBWbMG9TUogi9liNw--&latitude=0.1&longitude=0.1&zoom=12&image_width=1024&image_height=1024";
    // FdoStringP ret = L"appid=YD-4g6HBf0_JX0yq2IsdnV1Ne9JTpKxQ3Miew--&amp;street=701+First+Avenue&city=Sunnyvale&state=CA"

    return ret;
}

FdoStringP FdoCMSYahooGetMapURL::EncodeXml()
{
    // TODO: shall we support this?
    return L"";
}

